<template>
  <el-row>
    <el-col span="auto" style="margin-right: 10px">
      <el-avatar :src="user.imgUrl"></el-avatar>
    </el-col>
    <el-col span="auto" style="color: #5a5e66">
      <el-row style="margin-bottom: 10px">
        <span style="margin-right: 30px">昵称：{{ user.nickname }}</span>
        <span style="margin-right: 30px">性别：
          <el-tag size="mini">{{ user.sex === 1 ? '男' : '女' }}</el-tag>
        </span>
        <span>账号状态：
          <el-tag size="mini" :type="tagType">{{ user.disableStatus === 0 ? '正常' : '封禁' }}</el-tag>
        </span>
      </el-row>
      <el-row>
        <span style="margin-right: 20px">手机号：{{ user.phone }}</span>
        <span>QQ 邮箱：{{ user.qqEmail }}</span>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { getBaseInfoById } from '@/api/auth/user'

export default {
  name: 'UserInfoCard',
  props: {
    userId: Number
  },
  data() {
    return {
      user: {}
    }
  },
  methods: {
    getUserInfo() {
      getBaseInfoById({
        id: this.userId
      }).then(res => {
        if (res.data.code === 200) {
          this.user = res.data.userBaseInfoVO
        } else {
          this.$message.error({
            message: res.data.message,
            duration: 1000
          })
        }
      })
    }
  },
  computed: {
    tagType() {
      return this.user.disableStatus === 0 ? 'success' : 'danger'
    }
  },
  created() {
    this.getUserInfo()
  },
  watch: {
    roleId() {
      this.getUserInfo()
    }
  }
}
</script>

<style scoped></style>
